/*
 * Copyright (c) 2018-2999 株洲天汉科技有限公司 All rights reserved.
 *
 * https://www.mall4j.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.yami.shop.api.controller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fasterxml.jackson.annotation.JsonView;
import com.yami.shop.bean.app.dto.PlanDto;
import com.yami.shop.bean.model.Plan;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.service.PlanService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author lanhai
 */
@RestController
@RequestMapping("/shop/plan")
@Tag(name = "计划管理接口")
@AllArgsConstructor
public class PlanController {

    private PlanService planService;

    

    /**
     * 置顶计划列表接口
     */
    @GetMapping("/topNoticeList")
    @Operation(summary = "置顶计划列表信息" , description = "获取所有置顶计划列表信息")
    @JsonView(PlanDto.NoContent.class)
    public ServerResponseEntity<List<PlanDto>> getTopNoticeList() {
        List<Plan> noticeList = planService.listNotice();
        List<PlanDto> noticeDtoList = BeanUtil.copyToList(noticeList, PlanDto.class);
        return ServerResponseEntity.success(noticeDtoList);
    }

    /**
     * 获取计划详情
     */
    @GetMapping("/info/{id}")
    @Operation(summary = "计划详情" , description = "获取计划id计划详情")
//    @JsonView(NoticeDto.WithContent.class)
    public ServerResponseEntity<PlanDto> getNoticeById(@PathVariable("id") Long id) {
        Plan notice = planService.getNoticeById(id);
        PlanDto noticeDto = BeanUtil.copyProperties(notice, PlanDto.class);
        return ServerResponseEntity.success(noticeDto);
    }

    /**
     * 计划列表
     */
    @GetMapping("/noticeList")
    @Operation(summary = "计划列表信息" , description = "获取所有计划列表信息")
    @Parameters({
    })
    public ServerResponseEntity<IPage<PlanDto>> pageNotice(PageParam<PlanDto> page,PlanDto noticeDto) {

        return ServerResponseEntity.success(planService.pageNotice(page,noticeDto));
    }
}
